package com.elinkway.infinitemovies.http.parser;

import com.elinkway.infinitemovies.bean.HotDownloadBean;
import com.elinkway.infinitemovies.bean.HotDownloadList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class HotDownloadParser extends LVideoMobileParser<HotDownloadList> {

	private JSONArray arr;
	private static final String NAME = "name";
	private static final String AID = "aid";

	@Override
	public HotDownloadList parse(JSONObject data) throws Exception {
		if(data == null || arr.length() < 1){
			return null;
		}
		HotDownloadList hotList = new HotDownloadList();
		List<HotDownloadBean> hotDownloadList = new ArrayList<>();
		HotDownloadBean bean = null;
		for(int i =0;i<arr.length();i++){
			JSONObject obj = arr.getJSONObject(i);
			if(obj != null){
				bean = new HotDownloadBean();
				bean.setAid(obj.optString(AID));
				bean.setName(obj.optString(NAME));
				hotDownloadList.add(bean);
			}
		}
		hotList.setHotList(hotDownloadList);
		return hotList;
	}

	@Override
	protected JSONObject getData(String data) throws JSONException {
		// TODO Auto-generated method stub
		arr = new JSONArray(data);
		data = "{\"data\":\"data\"}";
		return super.getData(data);
	}

}
